package com.aubrey.threadDemo.create;

import java.util.Random;

import com.aubrey.threadDemo.atomic.People;

public class ThreadLocalDemo {
	
	public static void main(String[] args) {
		
		ThreadLocal tl1 = new ThreadLocal();
		ThreadLocal<People> tl2 = new ThreadLocal<People>();
		tl1.set(new Random().nextInt());
		tl2.set(new People("main",99));
		System.out.println(tl1.get());
		for (int i = 0; i < 2; i++) {
			new Thread(()-> {
				tl1.set(new Random().nextInt());
				People p1 = new People(Thread.currentThread().getName(),11);
				tl2.set(p1);
				System.out.println(Thread.currentThread().getName()+":" +tl1.get());
				System.out.println(Thread.currentThread().getName()+":" +tl2.get());
			}).start();
		}
		while(Thread.activeCount() > 1) Thread.yield();
		System.out.println(tl1.get()+":" +tl2.get());
		
	}

}
